package com.andy.wan.android.mvp.ui.adapter;

import android.widget.TextView;

import com.andy.wan.android.R;
import com.andy.wan.android.mvp.bean.KnowledgeHierarchyData;
import com.andy.wan.android.mvp.ui.fragment.FeedArticleListFragment;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.donkingliang.labels.LabelsView;

import androidx.annotation.NonNull;

/**
 * @Author: luofan
 * @CreateDate: 2020/3/31 14:23
 * @Description:
 */
public class KnowledgeHierarchyAdapter extends BaseQuickAdapter<KnowledgeHierarchyData, BaseViewHolder> {

    public KnowledgeHierarchyAdapter() {
        super(R.layout.adapter_knowledge_hierarchy);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, KnowledgeHierarchyData item) {
        helper.setText(R.id.tv_name, item.getName());
        LabelsView labelsView = helper.getView(R.id.labels);
        labelsView.setLabels(item.getChildren(), new LabelsView.LabelTextProvider<KnowledgeHierarchyData>() {
            @Override
            public CharSequence getLabelText(TextView label, int position, KnowledgeHierarchyData data) {
                return data.getName();
            }
        });
        labelsView.setOnLabelClickListener(new LabelsView.OnLabelClickListener() {
            @Override
            public void onLabelClick(TextView label, Object data, int position) {
                KnowledgeHierarchyData bean = (KnowledgeHierarchyData) data;
                FeedArticleListFragment.startMe(mContext, bean.getName(), FeedArticleListFragment.TYPE_KNOWLEDGE, bean.getId());
            }
        });
    }
}
